package com.story.aistory.controller;


import com.story.aistory.domain.dto.UserDTO;
import com.story.aistory.domain.dto.UserLoginDTO;
import com.story.aistory.domain.po.Result;
import com.story.aistory.domain.po.Users;
import com.story.aistory.domain.vo.UserLoginVO;
import com.story.aistory.service.IUsersService;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.catalina.User;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hui
 * @since 2025-03-12
 */
@RestController
@RequestMapping("/users")
@RequiredArgsConstructor
@Slf4j
@Tag(name = "用户相关接口", description = "用户相关接口")
public class UsersController {


    private final IUsersService usersService;

    @Operation(summary = "测试接口", description = "测试接口")
    @GetMapping("/hello")
    public String hello() {
        log.info("hello");
        return "hello";
    }

    @PostMapping("/login")
    @Operation(summary = "用户登录接口")
    public Result<UserLoginVO> login(@RequestBody UserLoginDTO userLoginDTO) {
        log.info("用户登录接口");
        UserLoginVO loginVO = usersService.login(userLoginDTO);
        return Result.success(loginVO) ;
    }

    //保存用户信息
    @PostMapping("/save")
    @Operation(summary = "保存用户信息")
    public Result save(@RequestBody UserDTO userDTO) {
        return usersService.saveUserData(userDTO);
    }
    //头像上传
    @PostMapping("/uploadAvatar")
    @Operation(summary = "头像上传")
    public Result uploadAvatar(@RequestParam("file") MultipartFile mpFile){
        return usersService.uploadAvatar(mpFile);
    }
    @GetMapping("/getUserData")
    @Operation(summary = "请求获取用户信息")
    public Result<Users> getUser() {
        return   usersService.getUser();
    }
    // 修改用户信息
    @PostMapping("/updateUserData")
    @Operation(summary = "修改用户信息")
    public Result updateUserData(@RequestBody Users users) {
        return usersService.updateUserData(users);
    }
}
